package Logic;

import java.util.ArrayList;

import view.InputInterface;
import Data.Record;
import Data.DataReaderInterface;
import Data.Manager;
import Data.ManagerDataReader;
import Data.Administrator;
import Data.AdministratorDataReader;

import view.LoginPanel;
public class LoginController {
	private boolean login = false;
	private DataReaderInterface reader;
	private InputInterface input;
	private ManagerDataReader mreader;
	private AdministratorDataReader areader;
	public LoginController(){
	}
	
public LoginController(InputInterface inpuInterface){
	login = false;
     reader = null;
	input = inpuInterface;
		
	
	}
	
    public boolean Login(){
		int flag=0;
		String temp = input.getInputInfo();
		String[] t=temp.split(",");
		if(t[0].equals("administrator")){
			reader=areader;
				if(reader.getRecordByID(Integer.parseInt(t[1]))==null){
					System.out.println("Login success");
					flag=1;
			}else{
				System.out.println("Login failed");
				}
			}
		else
		{
			   reader=mreader;
					if(reader.getRecordByID(Integer.parseInt(t[1]))==null){
						System.out.println("Login success");
						flag=1;
				}else{
					System.out.println("Login failed");
					}
		}
	if(flag==0)
		return false;
	else
		return true;
		
	}
}







